package com.example.itshome.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.example.itshome.R;
import com.example.itshome.adapter.SignUpActivityRecycleViewAdapter;
import com.example.itshome.entity.ActivityEntity;
import com.example.itshome.network.AbstractRecycleVIewGetRequest;
import com.example.itshome.network.GetFinishActivityRequest;
import com.example.itshome.network.GetSignedUpActivityRequest;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 * create an instance of this fragment.
 */
public class SignedUpActivityItemFragment extends Fragment {

    private RecyclerView mRecycleView;
    private List<ActivityEntity> mRecycleViewData;
    private ActivityPageType pageType;
    public enum ActivityPageType{
        ALL,OVER
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view=inflater.inflate(R.layout.fragment_signed_up_acticity_page_item, container, false);
        Bundle bundle=getArguments();
        if(bundle!=null){
            pageType= ActivityPageType.valueOf(bundle.getString("pageType"));
        }
        initFind(view);
        initRecycleView();
        return view;
    }

    void initFind(View v){
        mRecycleView=v.findViewById(R.id.rcv_signed_up_activity_page);
    }

    void initRecycleView(){
        mRecycleViewData=new ArrayList<>();

        mRecycleView.setLayoutManager(new LinearLayoutManager(getContext()));
        mRecycleView.setAdapter(new SignUpActivityRecycleViewAdapter(getContext(),mRecycleViewData));
        AbstractRecycleVIewGetRequest<ActivityEntity> request=null;
        switch (pageType){
            case ALL:request=new GetSignedUpActivityRequest(getActivity()); break;
            case OVER:request=new GetFinishActivityRequest(getActivity()); break;
        }
        request.setAdapter(mRecycleView.getAdapter());
        request.setCurrentData(mRecycleViewData);
        request.start();

    }

}